<?php


namespace app\common\model\tang;

use app\common\impl\Comm;
use app\common\model\CommonBaseModel;
use app\common\model\tang\Merchant;
use think\Facade\Db;

class MonthElectricityRecord extends CommonBaseModel implements Comm
{

    public function getAdminPageData($param = [], $order = 'now_time desc',$where=[])
    {
        $model = self::where($where);
        // TODO: Implement getAdminPageData() method.
        if (isset($param['merchant_id']) && $param['merchant_id']){
            $model->where('merchant_id','=',$param['merchant_id']);
        }
        if(isset($param['time'])&&$param['time']!=null){
            $time = explode('~',$param['time']);
            $model->whereBetweenTime('now_time',$time[0],$time[1]);
        }
        $data = $model->with(['merchant','watch'])->order($order)->page(PAGE)->limit(LIMIT)->select()->toArray();
        $count = $model->count("id");
        return parent::ajaxResult($data, $count);

    }

    public function merchant()
    {
        return $this->hasOne(Merchant::class,'id','merchant_id')->field('id,name');
    }
    public function watch()
    {
        return $this->hasOne(WatchMaintain::class,'id','watch_id')->field('id,pointName,rate');
    }
    public function delById($id)
    {
        // TODO: Implement delById() method.
    }

    public function doAll($data)
    {
        // TODO: Implement doAll() method.
        return parent::doAllData($data);
    }
}